var t = require("../../../@babel/runtime/helpers/defineProperty"), a = require("../../../mycomponent/yz_pay/yz_pay"), e = getApp();

Page({
    behaviors: [ a ],
    data: {
        showRich: !1,
        language: "",
        bannerindex: 1,
        mainCommentShow: !1,
        replyshow: !1,
        adminOperationshow: !1,
        releaseOperationshow: !1,
        amountRewardshow: !1,
        rewardPayshow: !1,
        stickid: "",
        detailsData: {},
        StickCommentData: [],
        replyName: "",
        replyContent: "",
        host_comment_id: "",
        second_comment_id: "",
        maincomment: "",
        readertype: 1,
        is_praise: !0,
        rewardArr: [ {
            value: 1,
            name: "5"
        }, {
            value: 2,
            name: "10"
        }, {
            value: 3,
            name: "20"
        }, {
            value: 4,
            name: "50"
        }, {
            value: 5,
            name: "100"
        } ],
        iPnoneBottomBol: !1,
        rewardArrselect: 99999,
        rewardArrmoney: "",
        rewardArrmoneytype: 2,
        btnData: [],
        rewardMoney: 0,
        commentManagement: !1,
        is_own: !1,
        commend_id: "",
        mulcommentsshow: !0,
        Height: 0,
        LastHeight: 0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        loading: !1,
        replyheight: 0,
        stick_flag: 0,
        recommend_flag: 0,
        reward_button: 1,
        rewardTypes: 0,
        reward_commend_id: 0,
        imgList: [],
        RewardMember: {},
        hide_comment: 0
    },
    onLoad: function(t) {
        if (t.stickId && 0 != Number(t.stickId)) {
            this.data.stickid = t.stickId, this.getMicroDetails(), this.getStickComment();
            try {
                wx.getStorageSync("iPhoneBottom") && this.setData({
                    iPnoneBottomBol: !0
                });
            } catch (t) {}
        } else wx.navigateBack({
            delta: 1
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    bindChangeBannerIndex: function(t) {
        this.setData({
            bannerindex: t.detail.current + 1
        });
    },
    onShow: function() {},
    adminBtn: function(t) {
        var a = this, i = t.currentTarget.dataset.typenum, n = {};
        n.tid = this.data.stickid, 1 == i ? (n.state = 1 == this.data.recommend_flag ? 0 : 1, 
        n.operation = 1) : 2 == i && (n.state = 1 == this.data.stick_flag ? 0 : 1, n.operation = 2);
        var s = e.getNetAddresss("plugin.micro-communities.api.trick.changeOperation");
        e._postNetWork({
            url: s,
            showToastIn: !1,
            data: n,
            success: function(t) {
                var e = t.data;
                if (wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }), 1 == e.result) if (1 == i) {
                    var n = 1 == a.data.recommend_flag ? 0 : 1;
                    a.setData({
                        recommend_flag: n
                    });
                } else if (2 == i) {
                    var s = 1 == a.data.recommend_flag ? 0 : 1;
                    a.setData({
                        stick_flag: s
                    });
                }
                a.setData({
                    adminOperationshow: !1
                });
            }
        });
    },
    onShareTimeline: function() {
        return {
            title: this.data.detailsData.title ? this.data.detailsData.title : ""
        };
    },
    onShareAppMessage: function() {
        return {
            title: this.data.detailsData.title ? this.data.detailsData.title : "",
            path: "/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=" + this.options.stickId
        };
    },
    amountRewardshowbtn: function() {
        this.setData({
            amountRewardshow: !1
        });
    },
    getMicroDetails: function() {
        var a = this, i = {
            tid: this.data.stickid
        }, n = e.getNetAddresss("plugin.micro-communities.api.trick.getStrickDetail");
        e._postNetWork({
            url: n,
            showToastIn: !1,
            data: i,
            success: function(e) {
                var i = e.data;
                if (1 == i.result) if (a.setData({
                    detailsData: i.data,
                    stick_flag: i.data.is_top,
                    recommend_flag: i.data.is_recommend,
                    reward_button: i.data.reward_button,
                    hide_comment: i.data.hide_comment
                }), a.data.detailsData && (1 == a.data.detailsData.is_manager ? a.setData({
                    readertype: 3
                }) : 1 == a.data.detailsData.is_own && a.setData({
                    readertype: 2
                }), 1 == a.data.detailsData.is_manager ? a.setData({
                    is_praise: !0
                }) : a.setData({
                    is_praise: !1
                })), a.data.detailsData.contents.indexOf("micro-panel-body") > -1 || a.data.detailsData.contents.indexOf("</p>") > -1 || a.data.detailsData.contents.indexOf("</div>") > -1) a.setData({
                    showRich: !0
                }); else {
                    var n = a.data.detailsData.contents.split("\n");
                    a.setData(t({
                        showRich: !1
                    }, "detailsData.contents", n));
                } else wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    pageInit: function() {
        this.data.page = 1, this.data.total_page = 0, this.data.isLoadMore = !0, this.data.loading = !1;
    },
    getStickComment: function() {
        var t = this;
        t.pageInit();
        var a = {
            tid: this.data.stickid
        }, i = e.getNetAddresss("plugin.micro-communities.api.trick.getStickComment");
        e._postNetWork({
            url: i,
            showToastIn: !1,
            data: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.data.total_page = e.data.last_page, t.setData({
                    StickCommentData: e.data.data
                }), e.data.last_page == e.data.current_page ? t.setData({
                    mulcommentsshow: !1
                }) : e.data.last_page > e.data.current_page && t.setData({
                    mulcommentsshow: !0
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    gotoCart: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    toShop: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + a
        });
    },
    toGood: function(t) {
        var a = t.currentTarget.dataset.good_id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    attentionBtn: function() {
        this.data.detailsData.is_follow ? this.cancelAttention() : this.addAttention();
    },
    cancelAttention: function() {
        var t = this, a = {
            uid: this.data.detailsData.user_id
        }, i = e.getNetAddresss("plugin.micro-communities.api.user.delFollow");
        e._postNetWork({
            url: i,
            showToastIn: !1,
            data: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    "detailsData.is_follow": !1
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    addAttention: function() {
        var t = this, a = {
            user_id: this.data.detailsData.user_id
        }, i = e.getNetAddresss("plugin.micro-communities.api.user.addFollow");
        e._postNetWork({
            url: i,
            showToastIn: !1,
            data: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    "detailsData.is_follow": !0
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    managementBtn: function() {
        1 == this.data.readertype || (2 == this.data.readertype ? this.setData({
            releaseOperationshow: !0
        }) : 3 == this.data.readertype && this.setData({
            adminOperationshow: !0
        }));
    },
    replyCommentsBtn: function(t) {
        var a = t.currentTarget.dataset.hostcommentid, e = t.currentTarget.dataset.secondcommentid, i = t.currentTarget.dataset.uname, n = t.currentTarget.dataset.content, s = t.currentTarget.dataset.isown;
        this.setData({
            host_comment_id: a,
            second_comment_id: e,
            replyContent: "",
            replyName: i,
            replyshowcontent: n
        }), console.log(this.data.replyContent), 1 == s ? this.setData({
            is_own: !0
        }) : this.setData({
            is_own: !1
        }), this.setData({
            commentManagement: !0
        });
    },
    praiseBtn: function(t) {
        var a = t.currentTarget.dataset.hostcommentid, e = t.currentTarget.dataset.secondcommentid, i = t.currentTarget.dataset.index, n = t.currentTarget.dataset.chilindex;
        if (1 == t.currentTarget.dataset.ispraise) return wx.showToast({
            icon: "none",
            title: "你已赞过该贴",
            duration: 1500
        }), !1;
        this.getPraiseData(a, e, i, n, "");
    },
    getPraiseData: function(a, i, n, s, o) {
        var r = this, d = {}, c = e.getNetAddresss("plugin.micro-communities.api.trick.givePraise");
        a || (d.tid = r.data.stickid), d.comment_id = a && i ? i : a, e._postNetWork({
            url: c,
            showToastIn: !1,
            data: d,
            success: function(e) {
                var d = e.data;
                if (1 == d.result) {
                    var c, m;
                    if ("main" == o) r.setData({
                        "detailsData.praise_num": r.data.detailsData.praise_num ? r.data.detailsData.praise_num + 1 : 1
                    }); else if (a && i) r.setData((t(c = {}, "StickCommentData.[" + n + "].child[" + s + "].is_praise", 1), 
                    t(c, "StickCommentData.[" + n + "].child[" + s + "].praise_num", r.data.StickCommentData[n].child[s].praise_num ? r.data.StickCommentData[n].child[s].praise_num + 1 : 1), 
                    c)); else r.setData((t(m = {}, "StickCommentData[" + n + "].is_praise", 1), t(m, "StickCommentData[" + n + "].praise_num", r.data.StickCommentData[n].praise_num ? r.data.StickCommentData[n].praise_num + 1 : 1), 
                    m));
                    wx.showToast({
                        icon: "none",
                        title: d.msg,
                        duration: 1500
                    });
                } else wx.showToast({
                    icon: "none",
                    title: d.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    mulchMeatsShowBtn: function() {
        this.setData({
            mulcommentsshow: !1
        }), this.getMoreData();
    },
    subMainCommentBtn: function() {
        this.setData({
            maincomment: "",
            mainCommentShow: !0
        });
    },
    moneyShow: function(a) {
        var e;
        this.setData((e = {
            rewardArrmoney: "",
            rewardArrselect: 9999,
            rewardMoney: 0,
            amountRewardshow: !0,
            rewardTypes: a.currentTarget.dataset.type,
            reward_commend_id: a.currentTarget.dataset.id || 0
        }, t(e, "RewardMember.img", a.currentTarget.dataset.memberimg || this.data.detailsData.has_one_stick_user.avatar), 
        t(e, "RewardMember.name", a.currentTarget.dataset.name || this.data.detailsData.has_one_stick_user.nickname), 
        e));
    },
    isPraiseBtn: function() {
        if (1 == this.data.detailsData.is_praise) return wx.showToast({
            icon: "none",
            title: "你已赞过该贴",
            duration: 1500
        }), !1;
        this.getPraiseData("", "", "", "", "main");
    },
    subMainBtn: function() {
        this.data.maincomment ? (this.setData({
            mainCommentShow: !1
        }), this.getReplyComments("main")) : wx.showToast({
            icon: "none",
            title: "请输入你的精彩评论",
            duration: 1500
        });
    },
    getReplyComments: function(a) {
        var i = this, n = {
            image: this.data.imgList
        }, s = e.getNetAddresss("plugin.micro-communities.api.trick.comments");
        n.tid = i.data.stickid, n.content = "main" == a ? i.data.maincomment : i.data.replyContent, 
        "reply" == a && (this.data.host_comment_id && (n.host_comment_id = this.data.host_comment_id), 
        this.data.second_comment_id && (n.second_comment_id = this.data.second_comment_id)), 
        e._postNetWork({
            url: s,
            showToastIn: !1,
            data: n,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (i.setData(t({
                    imgList: []
                }, "detailsData.comments_num", i.data.detailsData.comments_num + 1)), i.getStickComment(), 
                wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    replySubmitBtn: function() {
        this.data.replyContent ? (this.setData({
            replyshow: !1
        }), this.getReplyComments("reply")) : wx.showToast({
            icon: "none",
            title: "请输入回复内容",
            duration: 1500
        });
    },
    dminBtn: function(t) {
        var a = this, i = {};
        i.tid = a.data.stickid, 1 == t ? i.operation = 1 : 2 == t && (i.operation = 2);
        var n = e.getNetAddresss("plugin.micro-communities.api.trick.changeOperation");
        e._postNetWork({
            url: n,
            showToastIn: !1,
            data: i,
            success: function(t) {
                var e = t.data;
                e.result, a.setData({
                    adminOperationshow: !1
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    deleteBtn: function() {
        var t = this, a = {}, i = e.getNetAddresss("plugin.micro-communities.api.trick.delTrick");
        a.tid = t.data.stickid, e._postNetWork({
            url: i,
            showToastIn: !1,
            data: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }), t.setData({
                    releaseOperationshow: !1,
                    adminOperationshow: !1
                }), wx.redirectTo({
                    url: "/packageC/micro_communities/microIndex/microIndex"
                })) : (t.setData({
                    releaseOperationshow: !1,
                    adminOperationshow: !1
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {}
        });
    },
    adCancel: function() {
        this.setData({
            adminOperationshow: !1
        });
    },
    reEditBtn: function() {
        1 != this.data.detailsData.is_pc ? wx.navigateTo({
            url: "/packageC/micro_communities/microEdit/microEdit?stickid=" + this.data.stickid
        }) : e.tips("PC端发布的帖子只能在PC端修改！");
    },
    reCancelBtn: function() {
        this.setData({
            releaseOperationshow: !1
        });
    },
    shorewardArrBtn: function(t) {
        var a = t.currentTarget.dataset.index;
        this.setData({
            rewardArrmoneytype: 1,
            rewardArrselect: a,
            rewardArrmoney: ""
        });
    },
    confirmRewardBtn: function() {
        this.setData({
            amountRewardshow: !1
        }), console.log(this.data.rewardArrmoneytype), 1 == this.data.rewardArrmoneytype ? this.setData({
            rewardMoney: parseInt(this.data.rewardArr[this.data.rewardArrselect].name)
        }) : 2 == this.data.rewardArrmoneytype && this.setData({
            rewardMoney: this.data.rewardArrmoney
        }), e._isTextEmpty(this.data.rewardMoney) ? wx.showToast({
            icon: "none",
            title: "请输入或选择打赏金额",
            duration: 1500
        }) : this.data.rewardMoney <= 0 ? wx.showToast({
            icon: "none",
            title: "打赏金额必须大于0",
            duration: 1500
        }) : this.getPayData();
    },
    getPayData: function() {
        var t = this, a = e.getNetAddresss("plugin.micro-communities.api.reward-log.get-payment-buttons");
        e._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    var i = e.data.buttons;
                    t.setData({
                        btnData: i,
                        rewardPayshow: !0
                    });
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    payBtn: function(t) {
        var a, i, n = this, s = null;
        t.currentTarget ? (a = t.currentTarget.dataset.info.value, i = t.currentTarget.dataset.info.name, 
        s = t.currentTarget.dataset.info) : (a = t.value, i = t.name, s = t);
        var o = e.getNetAddresss("plugin.micro-communities.api.reward-log.index"), r = {
            pay_method: a,
            amount: this.data.rewardMoney,
            pay_name: i,
            client_type: "2"
        };
        0 == this.data.rewardTypes ? r.trick_id = this.data.stickid : (o = e.getNetAddresss("plugin.micro-communities.api.reward-log.commentPay"), 
        r.comment_id = this.data.reward_commend_id), e._postNetWork({
            url: o,
            showToastIn: !1,
            data: r,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (n.setData({
                    rewardPayshow: !1
                }), n.handleOtherPay(s, a, e.data)) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            }
        });
    },
    openImgPreview: function(t) {
        console.log(t), wx.previewImage({
            current: t.currentTarget.dataset.activeImg,
            urls: t.currentTarget.dataset.imgs
        });
    },
    rewardPayCancelBtn: function() {
        this.setData({
            rewardPayshow: !1
        });
    },
    replyBtn: function() {
        this.setData({
            replyshow: !0,
            commentManagement: !1
        });
    },
    delBtn: function() {
        this.data.host_comment_id && this.data.second_comment_id ? this.setData({
            commend_id: this.data.second_comment_id
        }) : this.setData({
            commend_id: this.data.host_comment_id
        }), this.setData({
            commentManagement: !1
        }), this.delReply();
    },
    delReply: function() {
        var t = this, a = {}, i = e.getNetAddresss("plugin.micro-communities.api.trick.delComment");
        a.commend_id = this.data.commend_id, e._postNetWork({
            url: i,
            showToastIn: !1,
            data: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.getStickComment(), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    replyCancelBtn: function() {
        this.setData({
            commentManagement: !1
        });
    },
    imgHeight: function(t) {
        var a = wx.getSystemInfoSync().windowWidth * t.detail.height / t.detail.width + "px";
        parseInt(a) > this.data.LastHeight && (this.setData({
            Height: a
        }), this.data.LastHeight = parseInt(a));
    },
    maincommentinp: function(t) {
        var a = t.detail.value;
        this.setData({
            maincomment: a
        });
    },
    rewardArrmoneyinp: function(t) {
        var a = t.detail.value;
        this.setData({
            rewardArrmoney: a
        });
    },
    replyContentinp: function(t) {
        var a = t.detail.value;
        this.setData({
            replyContent: a
        });
    },
    replyfocus: function(t) {
        var a = t.detail.height;
        this.setData({
            replyheight: a
        });
    },
    replyblur: function(t) {
        this.setData({
            replyheight: 0
        });
    },
    replyshowClose: function() {
        this.setData({
            replyshow: !1
        });
    },
    mainCommentShowClose: function() {
        this.setData({
            mainCommentShow: !1
        });
    },
    adminOperationshowClose: function() {
        this.setData({
            adminOperationshow: !1
        });
    },
    releaseOperationshowClose: function() {
        this.setData({
            releaseOperationshow: !1
        });
    },
    amountRewardshowClose: function() {
        this.setData({
            amountRewardshow: !1
        });
    },
    rewardPayshowClose: function() {
        this.setData({
            rewardPayshow: !1
        });
    },
    commentManagementClose: function() {
        this.setData({
            commentManagement: !1
        });
    },
    getMoreData: function() {
        if (this.data.mulcommentsshow) return !1;
        var t = this, a = {
            tid: this.data.stickid
        };
        t.data.isLoadMore = !1;
        var i = e.getNetAddresss("plugin.micro-communities.api.trick.getStickComment");
        this.data.page >= this.data.total_page ? t.setData({
            loading: !0
        }) : (t.data.page = this.data.page + 1, a.page = this.data.page, e._postNetWork({
            url: i,
            showToastIn: !1,
            data: a,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    var i = e.data.data;
                    t.setData({
                        StickCommentData: t.data.StickCommentData.concat(i)
                    });
                } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
            },
            fail: function(t) {}
        }));
    },
    helpPay: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        t && (a = t), wx.navigateTo({
            url: "/packageD/buy/payanotherDetail/payanotherDetail?order_id=" + this.data.detailsData.order_id + "&mid=" + a + "&pid=" + this.data.detailsData.has_one_stick_user.uid
        });
    },
    uploaderFun: function(t) {
        wx.showLoading({
            title: "加载中"
        });
        var a = this, i = e.getNetAddresss("upload.uploadPic");
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var e = t.tempFilePaths[0];
                wx.uploadFile({
                    url: i,
                    filePath: e,
                    name: "file",
                    success: function(t) {
                        var e = JSON.parse(t.data);
                        if (wx.hideLoading(), 1 == e.result) {
                            var i = a.data.imgList;
                            i.push(e.data.img_url), a.setData({
                                imgList: i
                            });
                        } else wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    delCommentIMg: function(t) {
        var a = t.target.dataset.index || t.currentTarget.dataset.index;
        this.data.imgList.splice(a, 1), this.setData({
            imgList: this.data.imgList
        });
    },
    gotoHome: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageC/micro_communities/microhomepage/microhomepage?micuid=" + a
        });
    }
});